package com.itheima.controller;

import com.alibaba.fastjson.JSON;
import com.itheima.service.IndexService;
import org.aspectj.lang.annotation.AfterReturning;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IndexService indexService;

    @GetMapping("/getBlogContributeCount")
    public String getBlogContributeCount(){
        Map blogContributeCount = indexService.getBlogContributeCount();

        Map map = new HashMap();
        map.put("code","success");
        map.put("data",blogContributeCount);
        return JSON.toJSONString(map);

    }

    @GetMapping("/getBlogCountByBlogSort")
    public String getBlogCountByBlogSort(){
        List<Map> blogCountByBlogSort = indexService.getBlogCountByBlogSort();
        HashMap map = new HashMap();
        map.put("code","success");
        map.put("data",blogCountByBlogSort);

        return JSON.toJSONString(map);
    }

    @GetMapping("/getBlogCountByTag")
    public String getBlogCountByTag(){
        List<Map> blogCountByTag = indexService.getBlogCountByTag();
        HashMap map = new HashMap();
        map.put("code","success");
        map.put("data",blogCountByTag);

        return JSON.toJSONString(map);
    }

    @GetMapping("/getVisitByWeek")
    public String getVisitByWeek(){
        Map visitByWeek = indexService.getVisitByWeek();

        HashMap map = new HashMap();
        map.put("code","success");
        map.put("data",visitByWeek);
        return JSON.toJSONString(map);
    }

    @GetMapping("/init")
    public String init(){
        Map init = indexService.init();
        HashMap map = new HashMap();
        map.put("code","success");
        map.put("data",init);
        return JSON.toJSONString(map);
    }
}
